/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa036is.validators;

import cz.muni.fi.pa036is.dto.MatchFormTO;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 *
 * @author Kuba
 */
public class MatchValidator implements Validator{

    @Override
    public boolean supports(Class<?> type) {
        return MatchFormTO.class.equals(type);
    }

    @Override
    public void validate(Object o, Errors errors) {
        
        ValidationUtils.rejectIfEmpty(errors, "dateAndTime", "dateAndTime.empty", "Date and time cannot be empty.");   
        
        MatchFormTO match = (MatchFormTO) o;
        
        if (match.getPlayer1Id() == match.getPlayer2Id()) {
            errors.reject("player2id", "Player 1 cannot be same as player 2");
        }
    }
    
}
